<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="../css/main.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" media="screen" href="../css/validator.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.validate.js"></script>
<script type="text/javascript" src="../js/jquery.validate.message_cn.js"></script>
<script language="javascript" type="text/javascript" src="../js/datecontrols/WdatePicker.js"></script>
</head>
<body>


<div class="navitop">
	<a id="generate_code_type" class="button" href="active_code.php?action=type"><span>礼包卡号类别管理</span></a>
	<a id="generate_code" class="button" href="active_code.php?action=make"><span>生成礼品卡号</span></a>
	<a id="generate_code" class="button" href="active_code.php?action=list"><span>礼品卡号列表</span></a>
</div>

<{if $act == 'make'}>

<form action="?action=make&op=generate" method="post" id="generateCodeForm">
<table class="tb_main">
	<tr class="tb_title"><th colspan="2">生成礼品卡号设置</th></tr>
	<tr><td>礼包卡类型</td>
	<td><select name="code_types">
				<{foreach from=$code_types key=key item=value }>
				<option value="<{$value.id}>" <{if $code_type == $value.id}>selected<{/if}>><{$value.act_type}></option>	
				<{/foreach}>
			</select>
	</td></tr>
	<tr><td>礼包卡号数量</td><td><input type="text" name="num" id="num" size="20" /></td></tr>
	<tr><td>礼包卡号长度</td><td><input type="text" name="length" id="length" size="20" /></td></tr>
	<tr><td colspan="2">
	<input type="submit" value="确定" /> 
	<input type="reset" value="重置"/></td></tr>
</table>
</form>

<script type="text/javascript">
$(document).ready(function() {
    $("#generateCodeForm").validate({
	    	rules: { 
    				num: { required: true, range: [1, 2000]}, 
    				length:{ required: true, range: [1, 50]}
    		}
        });
});
</script>

<{elseif $act=='type'}>

<form action="?action=type&op=add" method="post">
<div>
	<label>请输入新的礼包卡类型</label>
	<input type="text" id="" name="code_type_name" size="30"/>
	<input type="submit" value="增加"/>
</div>
</form>

<table class="tb_main">
	<tr class="tb_title"><th colspan="3">礼包卡类型</th></tr>
	<tr><td>礼包卡类型ID</td><td>礼包卡类型</td><td>操作</td></tr>
	<tr><td>241</td>
			<td><a href="?action=list&op=filter&codeTypes=241">封测礼包</a></td>
			<td><a  href="?action=make&code_type=241">生成礼品卡号</a> | (已有固定类型，不能删除) </td>
	</tr>
	<tr><td>242</td>
			<td><a href="?action=list&op=filter&codeTypes=242">至尊百金礼盒</a></td>
			<td><a  href="?action=make&code_type=242">生成礼品卡号</a> | (已有固定类型,不能删除) </td>
	</tr>
	<tr><td>243</td>
			<td><a href="?action=list&op=filter&codeTypes=243">VIP至尊礼包</a></td>
			<td><a  href="?action=make&code_type=243">生成礼品卡号</a> | (已有固定类型,不能删除) </td>
	</tr>
	<{foreach from=$actTypes key=key item=value }>
	<tr><td><{$value.id}></td>
			<td><a href="?action=list&op=filter&codeTypes=<{$value.id}>"><{$value.act_type}></a></td>
			<td><a  href="?action=make&code_type=<{$value.id}>">生成礼品卡号</a> |
					<a onclick="return check('local_delete');" href="?action=type&op=delete&typeId=<{$value.id}>">删除</a>
			</td>
	</tr>
	<{/foreach}>
</table>

<{elseif $act == 'list'}>

<form action="?action=list&op=filter" method="post" >


<div class="filterDiv">
			<label class="filter_label">礼包卡号</label>
			<input type="text" name="act_code" size="50" value="<{$act_code}>"/><br/>

			<label class="filter_label">生成时间</label>
			<input name="generate_time" type="text" id="generate_time" size="50" class="Wdatetime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
			
			<label class="filter_label">发送时间</label>
			<input name="send_time" type="text" id="send_time" size="50" class="Wdatetime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/><br/>

			<label class="filter_label">礼包卡类型</label>
			<select name="codeTypes">
					<option value="0">全部礼包卡类型</option>
					<{foreach from=$actTypes key=key item=value }>
					<option value="<{$value.id}>" <{if $value.id == $codeType}>selected<{/if}>><{$value.act_type}></option>	
					<{/foreach}>
			</select>
			
			<label class="filter_label">礼包卡个数</label>
			<input type="text" size="5" value="<{$codeNum}>" name="codeNum"/>
			
			<label class="filter_label">是否使用过</label>
			<select name="is_used">
					<option value="0" selected="selected">全部</option>
					<option value="1"   <{if $is_used == 1}> selected <{/if}>>尚未使用</option>
					<option value="2"  <{if $is_used == 2}> selected <{/if}>>已使用</option>
			</select>
			
			<label class="filter_label">目标服务器</label>
			<select name="server">
					<option value="0">全部</option>
					<{foreach from=$server_list key=key item=value}>
					<option value="<{$value.server_id}>" <{if $value.server_id == $server}> selected<{/if}> ><{$value.server_name}></option>
					<{/foreach}>
			</select>
			
			<input type="submit" value="查询" name="filter"/>	
</div>


<table class="tb_main">
		<tr><td class="td_title" width="80">游戏平台</td>
		<td class="td_input" colspan="2">
		<select name="platform_id[]">
		<{foreach from=$platforms key=key item=value}>   
			<option value="<{$value.id}>"><{$value.name}></option>
		<{/foreach}>
		</select>	
		</td>
	</tr>
	
	<tr>
		<td class="td_title">服务器列表</td>
		<td class="td_input" colspan="1">
		<{foreach from=$server_list key=key item=value}>   
			<input name="server_id[]" type="checkbox" value="<{$value.server_id}>" />
			<label><{$value.server_name}></label>
		<{/foreach}>	
		</td>
	</tr>
	
	<tr><td colspan="2">
			<input type="submit" value="发送至单服" name="send"  onclick="return check('send');"   style="width: 100px;">
			<input type="submit" value="从单服删除" name="remote_delete"  onclick="return check('remote_delete');"   style="width: 100px;">
			<input type="submit" value="本地删除" name="local_delete"  onclick="return check('local_delete');"   style="width: 100px;">
			</td>
	</tr>
	
</table>

</form>

<table class="tb_main">
	<tr class="tb_title"><th colspan="8">本地已经生成的礼品卡号列表</th></tr>
	<tr><td>id</td><td>礼包卡类型</td><td>礼品卡号</td><td>生成时间</td><td>状态</td><td>发送时间</td><td>目标服务器</td></tr>
	<{foreach from=$codes key=key item=value}>
	<tr><td><{$value.id}></td>
			<td><{$value.act_type}></td>
			<td><{$value.code}></td>
			<td><{$value.created_date}></td>
			<td><{if $value.status == 1}>尚未使用
					<{elseif $value.status == 2}><span style="color: blue;">已经发送至单服</span>
					<{else}>单服已经删除<{/if}></td>
			<td><{if $value.status == 1}>无<{elseif $value.status == 2}><{$value.last_modified_date}><{/if}></td>
			<td><{if $value.status == 1}>无<{elseif $value.status == 2}><{$value.server_id}><{/if}></td>
	</tr>
	<{/foreach}>
</table>

<{/if}>

<!--

$("#generate_code_type").fancybox({
	'titlePosition'		: 'inside',
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'callbackOnClose': function(){window.location.href=window.location.href;}
});
-->
<script type="text/javascript">

//生成礼品卡号
function generate()
{
	var num = $('#num').val();
	var length = $('#length').val();
	$.getJSON(
		'active_code.php?act=generate',
		{num:num,length:length},
		function(callback)
		{
			if(callback == 1)
			{
				alert('ok');
				return true;
			}
			else
			{
				alert('false');
				return false;
			}
		}
	);
}

//发送前校验
function check(type)
{
	if(type == 'send')
	{
		var flag = confirm('是否将选定的礼品卡发送至指定的单服?');
	}
	else if(type == 'remote_delete')
	{
		var flag = confirm('是否将选定的礼品卡从指定的单服删除?');
	}
	else if(type == 'local_delete')
	{
		var flag = confirm('是否在本地删除选定的礼品卡?');
	}
	
	if(flag) 
	{
		return true;
	}
	else
	{
		return false;
	}
}

</script>

</body>
</html>